﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace StateManager
{
    class ContinueScreen : GenericScreenCode
    {
        // this screen does nothing.  Just tells the player info.

        // I'm serious.
        Texture2D box;
        string message;

        public event EventHandler<PlayerEventHandler> yes;

         public ContinueScreen(string message)
            : this(message, true)
        {

        }

        public ContinueScreen(string message, bool includeUsage)
        {
            const string usageText = "\nPress the A button or Enter to continue";

            if (includeUsage)
                this.message = message + usageText; // if the include usage flag is set, the control instructions are given as well.
            else
                this.message = message;

            IsPopup = true; // the messagebox appears above all other windows
        }

        public override void LoadContent()
        {
            ContentManager content = SManager.Game.Content;

            box = content.Load<Texture2D>("images/ConfirmBox");
        }

        public override void HandleInput(Input input)
        {
            PlayerIndex pIndex;
            base.HandleInput(input);

            if (input.IsMenuSelect(ControllingPlayer, out pIndex))
            {
                if (yes != null)
                    yes(this, new PlayerEventHandler(pIndex));

                ExitScreen();
            }
        }


        public override void Draw(GameTime gameTime)
        {
            //base.Draw(gameTime);

            SpriteBatch spriteBatch = SManager.SpriteBatch;
            SpriteFont font = SManager.SpriteFont;

            Viewport view = SManager.GraphicsDevice.Viewport;
            Vector2 viewSize = new Vector2(view.Width, view.Height);
            Vector2 textSize = font.MeasureString(message);
            Vector2 textPosition = (viewSize - textSize) / 2;

            Rectangle backgroundRect = new Rectangle((int)textPosition.X,
                                                     (int)textPosition.Y,
                                                     (int)textSize.X,
                                                     (int)textSize.Y);
            // the rectangle is used to measure out the messagebox background so that it's the size of the text and no more.

            spriteBatch.Begin();

            spriteBatch.Draw(box, backgroundRect, Color.White);

            spriteBatch.DrawString(font, message, textPosition, Color.White);

            spriteBatch.End();



        }

    }
}
